package com.zxk.api.dto;


import com.zxk.core.common.constant.FundConstant;
import com.zxk.core.common.model.FundAnalysise;
import org.apache.commons.lang3.StringUtils;

/**
 * 对FundAnalysise的数据进行计算，属于数据传输
 */
public class FundAnalysiseDto {
    /**
     * 近1月盈利收益率
     */
    private String oneMonthEarningsYield;
    /**
     * 近3月盈利收益率
     */
    private String threeMonthEarningsYield;
    /**
     * 近6月盈利收益率
     */
    private String sixMonthEarningsYield;
    /**
     * 近1年盈利收益率
     */
    private String oneYearEarningsYield;
    /**
     * 近2年盈利收益率
     */
    private String twoYearEarningsYield;
    /**
     * 近3年盈利收益率
     */
    private String threeYearEarningsYield;
    /**
     * 近1月市盈率
     */
    private String oneMonthPeRatio;
    /**
     * 近3月市盈率
     */
    private String threeMonthPeRatio;
    /**
     * 近6月市盈率
     */
    private String sixMonthPeRatio;
    /**
     * 近1年市盈率
     */
    private String oneYearPeRatio;
    /**
     * 近2年市盈率
     */
    private String twoYearPeRatio;
    /**
     * 近3年市盈率
     */
    private String threeYearPeRatio;


    /**
     * 基金单日数据
     */
    private FundAnalysise fundAnalysise;

    public String getOneMonthEarningsYield() {

        return oneMonthEarningsYield;
    }

    public String getThreeMonthEarningsYield() {
        return threeMonthEarningsYield;
    }

    public String getSixMonthEarningsYield() {
        return sixMonthEarningsYield;
    }

    public String getOneYearEarningsYield() {
        return oneYearEarningsYield;
    }

    public String getTwoYearEarningsYield() {
        return twoYearEarningsYield;
    }

    public String getThreeYearEarningsYield() {
        return threeYearEarningsYield;
    }

    public String getOneMonthPeRatio() {
        return oneMonthPeRatio;
    }

    public String getThreeMonthPeRatio() {
        return threeMonthPeRatio;
    }

    public String getSixMonthPeRatio() {
        return sixMonthPeRatio;
    }

    public String getOneYearPeRatio() {
        return oneYearPeRatio;
    }

    public String getTwoYearPeRatio() {
        return twoYearPeRatio;
    }

    public String getThreeYearPeRatio() {
        return threeYearPeRatio;
    }


    public FundAnalysise getFundAnalysise() {
        return fundAnalysise;
    }


    public FundAnalysiseDto(FundAnalysise fundAnalysise) {
        this.fundAnalysise = fundAnalysise;
        if(StringUtils.isNotBlank(this.fundAnalysise.getOneYearIncome())) {
            double val = Double.parseDouble(this.fundAnalysise.getOneYearIncome().replace("%", ""));
            this.oneYearPeRatio = (FundConstant.YI_BAI/val)+"";
            this.oneYearEarningsYield = (1/Double.parseDouble(this.oneYearPeRatio)) + "";
        }

        if(StringUtils.isNotBlank(this.fundAnalysise.getTwoYearIncome())) {
            double val = Double.parseDouble(this.fundAnalysise.getTwoYearIncome().replace("%", ""));
            this.twoYearPeRatio = (FundConstant.YI_BAI/val)+"";
            this.twoYearEarningsYield = (1/Double.parseDouble(this.twoYearPeRatio)) + "";
        }

        if(StringUtils.isNotBlank(this.fundAnalysise.getThreeYearIncome())) {
            double val = Double.parseDouble(this.fundAnalysise.getThreeYearIncome().replace("%", ""));
            this.threeYearPeRatio = (FundConstant.YI_BAI/val)+"";
            this.threeYearEarningsYield = (1/Double.parseDouble(this.threeYearPeRatio)) + "";
        }

        if(StringUtils.isNotBlank(this.fundAnalysise.getOneMonthIncome())) {
            double val = Double.parseDouble(this.fundAnalysise.getOneMonthIncome().replace("%", ""));
            this.oneMonthPeRatio = (FundConstant.YI_BAI/val)+"";
            this.oneMonthEarningsYield = (1/Double.parseDouble(this.oneMonthPeRatio)) + "";
        }

        if(StringUtils.isNotBlank(this.fundAnalysise.getThreeMonthIncome())) {
            double val = Double.parseDouble(this.fundAnalysise.getThreeMonthIncome().replace("%", ""));
            this.threeMonthPeRatio = (FundConstant.YI_BAI/val)+"";
            this.threeMonthEarningsYield = (1/Double.parseDouble(this.threeMonthPeRatio)) + "";
        }

        if(StringUtils.isNotBlank(this.fundAnalysise.getSixMonthIncome())) {
            double val = Double.parseDouble(this.fundAnalysise.getSixMonthIncome().replace("%", ""));
            this.sixMonthPeRatio = (FundConstant.YI_BAI/val)+"";
            this.sixMonthEarningsYield = (1/Double.parseDouble(this.sixMonthPeRatio)) + "";
        }
    }

    @Override
    public String toString() {
        return "FundAnalysiseDto{" +
                "oneMonthEarningsYield='" + oneMonthEarningsYield + '\'' +
                ", threeMonthEarningsYield='" + threeMonthEarningsYield + '\'' +
                ", sixMonthEarningsYield='" + sixMonthEarningsYield + '\'' +
                ", oneYearEarningsYield='" + oneYearEarningsYield + '\'' +
                ", twoYearEarningsYield='" + twoYearEarningsYield + '\'' +
                ", threeYearEarningsYield='" + threeYearEarningsYield + '\'' +
                ", oneMonthPeRatio='" + oneMonthPeRatio + '\'' +
                ", threeMonthPeRatio='" + threeMonthPeRatio + '\'' +
                ", sixMonthPeRatio='" + sixMonthPeRatio + '\'' +
                ", oneYearPeRatio='" + oneYearPeRatio + '\'' +
                ", twoYearPeRatio='" + twoYearPeRatio + '\'' +
                ", threeYearPeRatio='" + threeYearPeRatio + '\'' +
                ", fundAnalysise=" + fundAnalysise +
                '}';
    }
}
